package com.fqxiny.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fqxiny.lease.model.entity.*;
import com.fqxiny.lease.web.admin.mapper.*;
import com.fqxiny.lease.web.admin.service.LeaseAgreementService;
import com.fqxiny.lease.web.admin.service.RoomInfoService;
import com.fqxiny.lease.web.admin.vo.agreement.AgreementQueryVo;
import com.fqxiny.lease.web.admin.vo.agreement.AgreementVo;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 25312
* @description 针对表【lease_agreement(租约信息表)】的数据库操作Service实现
* @createDate 2025-03-25 19:55:24
*/
@Service
public class LeaseAgreementServiceImpl extends ServiceImpl<LeaseAgreementMapper, LeaseAgreement>
    implements LeaseAgreementService{
    @Autowired
    private LeaseAgreementMapper leaseAgreementMapper;
    @Autowired
    ApartmentInfoMapper  apartmentInfoMapper;
    @Autowired
    RoomInfoMapper roomInfoMapper;
    @Autowired
    PaymentTypeMapper paymentTypeMapper;
    @Autowired
    LeaseTermMapper leaseTermMapper;

    @Override
    public AgreementVo getAgreementVoById(Long id) {
        //1.查询租约信息
        LeaseAgreement leaseAgreement = leaseAgreementMapper.selectById(id);

        //2.查询公寓信息
        ApartmentInfo apartmentInfo = apartmentInfoMapper.selectById(leaseAgreement.getApartmentId());

        //3.查询房间信息
        RoomInfo roomInfo = roomInfoMapper.selectById(leaseAgreement.getRoomId());

        //4.查询支付方式
        PaymentType paymentType = paymentTypeMapper.selectById(leaseAgreement.getPaymentTypeId());

        //5.查询租期
        LeaseTerm leaseTerm = leaseTermMapper.selectById(leaseAgreement.getLeaseTermId());

        AgreementVo adminAgreementVo = new AgreementVo();
        BeanUtils.copyProperties(leaseAgreement, adminAgreementVo);
        adminAgreementVo.setApartmentInfo(apartmentInfo);
        adminAgreementVo.setRoomInfo(roomInfo);
        adminAgreementVo.setPaymentType(paymentType);
        adminAgreementVo.setLeaseTerm(leaseTerm);
        return adminAgreementVo;
    }

    @Override
    public Page<AgreementVo> agreementVoIPage(IPage<AgreementVo> page, AgreementQueryVo queryVo) {
        Page<AgreementVo> agreementVoPage = leaseAgreementMapper.agreementVoIPage(page, queryVo);
        System.out.println("========================================================================");
        List<AgreementVo> records = agreementVoPage.getRecords();
        for (AgreementVo record : records) {
            System.out.println("record = " + record);
        }
        return agreementVoPage;
    }
}




